package bottlepacker.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.Toolkit;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Label;


public class SixPack extends JFrame {

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SixPack frame = new SixPack();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SixPack() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(SixPack.class.getResource("/bottlepacker/resources/Bottle.jpg")));
		setTitle("Bottle Packer");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 423, 603);
		
		JPanel panel = new JPanel();
		GroupLayout groupLayout_1 = new GroupLayout(getContentPane());
		groupLayout_1.setHorizontalGroup(
			groupLayout_1.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout_1.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGap(5))
		);
		groupLayout_1.setVerticalGroup(
			groupLayout_1.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout_1.createSequentialGroup()
					.addGap(6)
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE)
					.addContainerGap())
		);
		
		JLabel lable_orderNum = new JLabel("Service Order #  1");
		
		JLabel label = new JLabel("");
		
		JLabel lblCokesAvaliable = new JLabel("Cokes Avaliable____");
		
		JLabel lblSpriteAvaliable = new JLabel("Sprite Avaliable ______");
		
		JButton btnPlaceOrder = new JButton("Place Order");
		
		JButton btnCancel = new JButton("Cancel");
		
		JLabel label_bottle1 = new JLabel("");
		label_bottle1.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		
		JLabel label_bottle2 = new JLabel("");
		label_bottle2.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		
		JLabel label_bottle3 = new JLabel("");
		label_bottle3.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		
		JLabel label_bottle5 = new JLabel("");
		label_bottle5.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		
		JLabel label_bottle4 = new JLabel("");
		label_bottle4.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		
		JLabel label_bottle6 = new JLabel("");
		label_bottle6.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		
		JLabel lblRightClickTo = new JLabel("Right Click to select soda");
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(lable_orderNum)
						.addComponent(label)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(1)
							.addComponent(lblCokesAvaliable)
							.addGap(18)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(btnPlaceOrder)
								.addComponent(lblSpriteAvaliable)))
						.addComponent(btnCancel)
						.addComponent(lblRightClickTo, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(label_bottle1)
							.addGroup(gl_panel.createSequentialGroup()
								.addPreferredGap(ComponentPlacement.UNRELATED)
								.addComponent(label_bottle2)))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(label_bottle3, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(label_bottle4, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(label_bottle5, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(label_bottle6, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(151, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lable_orderNum)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(label)
						.addComponent(lblRightClickTo))
					.addPreferredGap(ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(label_bottle1)
						.addComponent(label_bottle2))
					.addGap(18)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(label_bottle3, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_bottle4, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(label_bottle6, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_bottle5, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
					.addGap(43)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnCancel)
						.addComponent(btnPlaceOrder))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCokesAvaliable)
						.addComponent(lblSpriteAvaliable))
					.addContainerGap())
		);
		
		//Pop up bottle 6
		JPopupMenu popBottle6 = new JPopupMenu();
		addPopup(label_bottle6, popBottle6);
		
		JMenuItem popBottle6_coke = new JMenuItem("");
		popBottle6_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle6.add(popBottle6_coke);
		
		JMenuItem popBottle6_sprite = new JMenuItem("");
		popBottle6_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle6.add(popBottle6_sprite);
		
		
		//Pop up bottle 5
		JPopupMenu popBottle5 = new JPopupMenu();
		addPopup(label_bottle5, popBottle5);
		
		JMenuItem popBottle5_coke = new JMenuItem("");
		popBottle5_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle5.add(popBottle5_coke);
		
		JMenuItem popBottle5_sprite = new JMenuItem("");
		popBottle5_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle5.add(popBottle5_sprite);
		
		
		//Pop up bottle 4
		JPopupMenu popBottle4 = new JPopupMenu();
		addPopup(label_bottle4, popBottle4);
		
		JMenuItem popBottle4_coke = new JMenuItem("");
		popBottle4_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle4.add(popBottle4_coke);
		
		JMenuItem popBottle4_sprite = new JMenuItem("");
		popBottle4_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle4.add(popBottle4_sprite);
		
		//Pop up bottle 3
		JPopupMenu popBottle3 = new JPopupMenu();
		addPopup(label_bottle3, popBottle3);
		
		JMenuItem popBottle3_coke = new JMenuItem("");
		popBottle3_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle3.add(popBottle3_coke);
		
		JMenuItem popBottle3_sprite = new JMenuItem("");
		popBottle3_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle3.add(popBottle3_sprite);
		
		//Pop up bottle 2
		JPopupMenu popBottle2 = new JPopupMenu();
		addPopup(label_bottle2, popBottle2);
		
		JMenuItem popBottle2_coke = new JMenuItem("");
		popBottle2_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle2.add(popBottle2_coke);
		
		JMenuItem popBottle2_sprite = new JMenuItem("");
		popBottle2_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle2.add(popBottle2_sprite);
		
		//Pop up bottle 1
		JPopupMenu popBottle1 = new JPopupMenu();
		addPopup(label_bottle1, popBottle1);
		
		JMenuItem popBottle1_coke = new JMenuItem("");
		popBottle1_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle1.add(popBottle1_coke);
		
		JMenuItem popBottle1_sprite = new JMenuItem("");
		popBottle1_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle1.add(popBottle1_sprite);
		
		Label label_2 = new Label("New label");
		popBottle1.add(label_2);
		panel.setLayout(gl_panel);
		getContentPane().setLayout(groupLayout_1);
		
		
		//Menu Bar
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mnFile.add(mntmExit);
		
		JMenu mnEdit_1 = new JMenu("Edit");
		menuBar.add(mnEdit_1);
		
		JMenuItem mntmStuff = new JMenuItem("Stuff");
		mnEdit_1.add(mntmStuff);
		
		JMenu mnAbout = new JMenu("Info");
		menuBar.add(mnAbout);
		
		JMenuItem mntmInstructions = new JMenuItem("Instructions");
		mnAbout.add(mntmInstructions);
		
		JMenuItem mntmAbout = new JMenuItem("About");
		mnAbout.add(mntmAbout);
	}
	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
}
